﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

public class SkillSystem :MonoBehaviour{

	private static SkillSystem _instance;

	public static SkillSystem instance{
		get{
			if (_instance == null)
            {
                GameObject obj = new GameObject("SkillSystem");
                DontDestroyOnLoad(obj);
                _instance = obj.AddComponent<SkillSystem>();
            }
			return _instance;
		}
	}

    private void Awake()
    {
        runningList = new List<SkillEffectController>();
        cacheList = new List<SkillEffectController>();
    }

    //正在运行中的技能
    private List<SkillEffectController> runningList;

	//已经运行完毕的技能缓存起来重用
	private List<SkillEffectController> cacheList;

	private SkillEffectController getSKillEffect()
    {
		if (cacheList.Count > 0) {
			SkillEffectController sys = cacheList [0];
			cacheList.Remove (sys);
			return sys;
		}
		return new SkillEffectController ();
	}

	void Update()
    {
		foreach (SkillEffectController manager in runningList)
			manager.Update ();
	}

	//接口
	public void ShowSkill(GameObject caster,GameObject[] targets,SkillEffectVo vo){
        if (caster == null || targets == null || targets.Length == 0 || vo == null)
            return;
		SkillEffectController effect = getSKillEffect ();
		effect.Init (caster,targets,vo);
		runningList.Add (effect);
	}

}
